package com.jagochan.module.business.controller;


import com.jagochan.common.result.PageVO;
import com.jagochan.common.result.ResultUtils;
import com.jagochan.common.result.ResultVo;
import com.jagochan.module.business.pojo.vo.CommentVO;
import com.jagochan.module.business.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Validated
@Tag(name = "评论")
@RestController
@RequestMapping("/community/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @Operation(summary = "分页查询指定帖子的评论列表")
    @GetMapping("/page")
    public ResultVo<PageVO<CommentVO>> page(@Parameter(description = "帖子(文章)ID", example = "1") @NotNull(message = "帖子(文章)ID") Long articleId,
                                            @Parameter(description = "分页参数（页码）", example = "1") @Range(min = 1L, max = 100L, message = "页码不能小于1或大于100")
                                            int pageNo) {
        PageVO<CommentVO> pageVO = commentService.pageComment(articleId, pageNo);
        return ResultUtils.success("查询成功", pageVO);
    }
}
